<?php
/**
 *我的收藏
 */

namespace app\api\controller;


use think\Request;
use app\api\model\Collection as CollectionModel;
class Collection extends Common
{

    public function postAddCollection(Request $request)
    {
        $user_id = $this->checkLoginUser(true);

        $goods_id = $request->post('goods_id',0,'intval');


        if(empty($goods_id))
        {
            to_json_encode(400,'参数错误',['status'=>false]);

        }
        
        if(CollectionModel::addCollection($user_id,$goods_id))
        {
            to_json_encode(200,'success',['status'=>true]);

        }
        to_json_encode(400,'收藏失败',['status'=>false]);

    }
    public function postDeleteCollection(Request $request)
    {
        $user_id = $this->checkLoginUser(true);

        $goods_id = $request->post('goods_id',0,'intval');

        if(empty($goods_id))
        {
            to_json_encode(400,'参数错误',['status'=>false]);

        }

        if(CollectionModel::deleteCollectionByGoodsId($user_id,$goods_id))
        {
            to_json_encode(200,'success',['status'=>true]);

        }
        to_json_encode(400,'删除失败',['status'=>false]);

    }
    public function getList(Request $request)
    {
        $user_id = $this->checkLoginUser(true);
        $page = $request->param('page',1);
        to_json_encode(200,'success',CollectionModel::handleList(
            CollectionModel::getList($user_id,$page)
            ,$user_id));
    }
}